using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace CocoCube
{
    public class Camera
    {
        Vector3 position;

        public Vector3 Position
        {
            get { return position; }
            set { position = value; }
        }

        Vector3 target;

        public Vector3 Target
        {
            get { return target; }
            set { target = value; }
        }

        Vector3 up;

        public Vector3 Up
        {
            get { return up; }
            set { up = value; }
        }

        Matrix worldViewMatrix;

        public Matrix WorldViewMatrix
        {
            get 
            {
                if (isDirty) UpdateMatrix();
                return worldViewMatrix; 
            }
        }

        Matrix viewWorldMatrix;

        public Matrix ViewWorldMatrix
        {
            get 
            {
                if (isDirty) UpdateMatrix();
                return viewWorldMatrix; 
            }
        }

        bool isDirty = true;

        void UpdateMatrix() 
        {
            if (!isDirty) return;
            worldViewMatrix = Matrix.CreateLookAt(position, target, up);
            viewWorldMatrix = Matrix.Invert(worldViewMatrix);
            isDirty = false;
        }
    }
}
